when
also can be used as an expression. Whatever the selected branch evaluates
to is what the when
returns.
The when
will also have to be "exhaustive", having branches that cover every
possible scenario. Usually, that means that we need an else
branch.
You can learn more about this in:
Tags: